/*
 * DNA.cpp
 *
 *  Created on: Apr 19, 2011
 *      Author: James Harding
 */

#include <iostream>
#include <vector>
#include <stdio.h>
#include "DNA.h"
#include "FileIO.h"

using namespace std;

///Default constructor

/**For creating a DNA with no initial sequence*/
DNA::DNA(){
	DNA::DNAOriginalPosition = 0;
	DNAAlignedPosition = 0;
}

///DNA int constructor

/**This constructor takes a int and creates the size of a
 matrix from it*/
DNA::DNA(int originalSize){
	DNASequenceOriginal.resize(originalSize);
	DNAOriginalPosition = 0;
	DNAAlignedPosition = 0;
}

///DNA char vector constructor
/**This constructor takes a list of chars usually a list of DNA
 and creates and initializes all variables of DNA*/
DNA::DNA(vector<char> newDNASequence){
	try{
			DNASequenceOriginal = newDNASequence;
	}
	catch(exception){
		cout << "Error creating DNA Sequence" << endl;
                FileIO::Write("Error creating DNA Sequence");
	}

	DNAOriginalPosition = DNASequenceOriginal.size();
	DNAAlignedPosition = 0;
}

///DNA Destructor
DNA::~DNA(){

}

///Print original DNA sequence

/**This is used to print the origianal sequence to the screen and
 to write it to a file. This method is mainly used for visual comapason
 of DNA sequnces*/
void DNA::printDNASequenceOriginal(){
	for(unsigned int i = 0; i < DNASequenceOriginal.size(); i++){
		cout << DNASequenceOriginal[i];
        FileIO::Write(DNASequenceOriginal[i]);
	}
}

///Print aligned DNA sequence

/**This is used to print the aligned sequence to the screen and
 to write it to a file. This method is mainly used for visual comapason
 of DNA sequnces*/
void DNA::printDNASequenceAligned(){
	for(unsigned int i = 0; i < DNASequenceAligned.size(); i++){
			cout << DNASequenceAligned[i];
                        FileIO::Write(DNASequenceAligned[i]);
		}
}

///Resets the Aligned sequence matrix to 0
void DNA::clearAligned(){
	DNASequenceAligned.clear();
	DNAAlignedPosition = 0;
}

///Compaires residue to original DNA sequence

/**This method returns wether the residue matches the current residue
 in the original sequence that original position variable is pointing to*/
bool DNA::AddToDNASequenceOriginal(char residue){
	if((DNASequenceOriginal[DNAOriginalPosition] = residue)){
			DNAOriginalPosition++;
			return true;
		}
		else{
			return false;
		}
}

///Compaires residue to aligned DNA sequence

/**This method returns wether the residue matches the current residue
 in the aligned sequence that aligned position variable is pointing to*/
bool DNA::AddToDNASequenceAligned(char residue){
	if((DNASequenceAligned[DNAAlignedPosition] = residue)){
			DNAAlignedPosition++;
			return true;
		}
		else{
			return false;
		}
}

///Inserts at the begining

/**Is responsable for inserting a residue at the begining of a
 aligned DNA sequence*/
bool DNA::InsertAtBeginingAligned(char residue){
	try{
		DNASequenceAligned.insert(DNASequenceAligned.begin(), 1, residue);
		return true;
	}catch(exception){
		cout << "there was an error inserting at the beinging of the aligned sequence" << endl;
		return false;
	}
}

char DNA::getDNAatPositionOriginal(int position){
	return DNASequenceOriginal[position];
}

char DNA::getDNAatPositionAligned(int position){
	return DNASequenceAligned[position];
}

int DNA::getOriginalSize(){
	return DNASequenceOriginal.size();
}

int DNA::getAlignedSize(){
	return DNASequenceAligned.size();
}
